package com.niiwoo.civet.trade.service.local.newRefund.notify.mq;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.niiwoo.civet.trade.dao.entity.Project;
import com.niiwoo.civet.trade.dao.entity.ProjectBorrowerPlanNew;
import com.niiwoo.civet.trade.dao.mapper.ProjectBorrowerPlanNewMapperExt;
import com.niiwoo.civet.trade.dto.FollowWorkTaskAddDTO;
import com.niiwoo.civet.trade.service.local.newRefund.notify.dto.RefundNotifyDTO;
import com.niiwoo.civet.trade.service.local.newRefund.notify.enums.RefundNotifyEnum;

/**
 * 神盾标的逾期通知
 *  
 * 触发条件：标的逾期
 * 
 * @author: kevin.jia
 * @version 1.0.0
 */
@Component
public class ShenDunOverdueNotify extends MQRefundNotify {

	@Autowired
	private ProjectBorrowerPlanNewMapperExt projectBorrowerPlanNewMapperExt;
	
	@Override
	public Object bulidParam(RefundNotifyDTO refundNotifyDTO) {
		// 标的信息
		Project project = refundNotifyDTO.getProject();
        
		// 查询逾期期数（当前待还款最早的一期）
		ProjectBorrowerPlanNew projectBorrowerPlan = projectBorrowerPlanNewMapperExt.selectNextNotRefunPeriod(project.getProjectId());
		if (null == projectBorrowerPlan) {
			return null;
		}
        
        FollowWorkTaskAddDTO followWorkTaskAddDTO = new FollowWorkTaskAddDTO();
        followWorkTaskAddDTO.setProjectId(project.getProjectId());
        followWorkTaskAddDTO.setBorrowerMobile(project.getBorrowMobile());
        followWorkTaskAddDTO.setBorrowerPlanId(projectBorrowerPlan.getId());
        followWorkTaskAddDTO.setBorrowerUserId(projectBorrowerPlan.getUserId());
        followWorkTaskAddDTO.setBorrowerUserName(project.getBorrowUserName());
        followWorkTaskAddDTO.setRefundDate(projectBorrowerPlan.getRefundDate());
        followWorkTaskAddDTO.setApplyTime(project.getCreateTime());
        
        return followWorkTaskAddDTO;
	}

	@Override
	public RefundNotifyEnum getType() {
		return RefundNotifyEnum.SHENDUN_PROJECT_OVERDUE;
	}
}